home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / html / programs / cgiacc.bas < prev    next >
Encoding:
BASIC Source File  |  1995-02-18  |  7.6 KB  |  182 lines

  1. '----------------------------------------------------------------------
  2. '       ***************
  3. '       * CGITEST.BAS *
  4. '       ***************
  5. '
  6. ' Test CGI back-end for NCSA httpd for Windows. Generates HTML report
  7. ' detailing the stuff it got from the server via the interface.
  8. '
  9. ' Requires procedures in CGI.BAS. Set the VB project options to use
  10. ' Sub Main as the startup form.
  11. '
  12. ' Author:   Robert B. Denny <rdenny@netcom.com>
  13. '           June 7, 1994
  14. '----------------------------------------------------------------------
  15. Option Explicit
  16.  
  17. '
  18. '   Do a database lookup on one of two fields in a book database
  19. '
  20. ' CGI.BAS contains the "Sub Main()" entry point. That code initializes
  21. ' the CGI environment, then calls CGI_Main(), here. At this point, the
  22. ' output file is open, the input file (if any) is NOT. Use the Send()
  23. ' function to isolate yourself from the output file number, and as
  24. ' a convenient shortcut.
  25. '
  26. ' NOTE: ALWAYS use FreeFile() to get file numbers if you need to open
  27. '       files in your code!
  28. Sub CGI_Main ()
  29.     Dim Auth1First As String
  30.     Dim Auth1Last As String
  31.     Dim Auth2First As String
  32.     Dim Auth2Last As String
  33.     Dim ISBN As String
  34.     Dim Copyright As Integer
  35.     Dim Title As String
  36.    
  37.     Dim sel As String
  38.     Dim buf As String
  39.     Dim i As Integer
  40.     Dim MyDB As Database, MySet As Dynaset
  41.     Dim Query As String
  42.  
  43.     sel = LCase$(Mid$(CGI_LogicalPath, 2)) ' Skip leading "/"
  44.     Select Case sel
  45.     '
  46.     ' Search for Title
  47.     '
  48.     Case "title"
  49.         Query = "TITLE LIKE '*" & CGI_FormTuples(0).Value & "*' "
  50.         StartDBReply
  51.         If CGI_NumFormTuples < 1 Then
  52.             Send ("<H2>No Query Entered</H2>")
  53.         Else
  54.  
  55.             Set MyDB = OpenDatabase("C:\httpd\cgi-win\ibooks.MDB")   ' Open a database.
  56.             Set MySet = MyDB.CreateDynaset("Book Collection")
  57.             MySet.FindFirst Query
  58.             If MySet.NoMatch Then
  59.                 Send ("<H2>No Match in Database for Title " & CGI_FormTuples(0).Value & " </H2>")
  60.             Else
  61.                 Auth1First = "" & MySet.Fields("Author1FirstName").Value
  62.                 Auth1Last = "" & MySet.Fields("Author1LastName").Value
  63.                 Auth2First = "" & MySet.Fields("Author2FirstName").Value
  64.                 Auth2Last = "" & MySet.Fields("Author2LastName").Value
  65.                 ISBN = MySet.Fields("ISBNNumber")
  66.                 Title = MySet.Fields("Title")
  67.                 Send ("<H2>Match(s) for Title " & CGI_FormTuples(0).Value & " </H2>")
  68.                 Send ("<P>Title: " & Title & "</P>")
  69.                 Send ("<P>Author: " & Auth1First & " " & Auth1Last & "</P>")
  70.                 If Auth2Last <> "" Then
  71.                     Send ("<P>Author: " & Auth2First & " " & Auth2Last & "</P>")
  72.                 End If
  73.                 Send ("<P>ISBN Number: " & ISBN & "</P>")
  74.                 While MySet.NoMatch = False
  75.                     MySet.FindNext Query
  76.                     If MySet.NoMatch = False Then
  77.                         Send ("<HR>")
  78.                         Auth1First = "" & MySet.Fields("Author1FirstName").Value
  79.                         Auth1Last = "" & MySet.Fields("Author1LastName").Value
  80.                         Auth2First = "" & MySet.Fields("Author2FirstName").Value
  81.                         Auth2Last = "" & MySet.Fields("Author2LastName").Value
  82.                         ISBN = MySet.Fields("ISBNNumber")
  83.                         Title = MySet.Fields("Title")
  84.                         Send ("<P>Title: " & Title & "</P>")
  85.                         Send ("<P>Author: " & Auth1First & " " & Auth1Last & "</P>")
  86.                         If Auth2Last <> "" Then
  87.                             Send ("<P>Author: " & Auth2First & " " & Auth2Last & "</P>")
  88.                         End If
  89.                         Send ("<P>ISBN Number: " & ISBN & "</P>")
  90.                     End If
  91.                 Wend
  92.             End If
  93.             MySet.Close
  94.             MyDB.Close
  95.         End If
  96.  
  97.     Case "author"
  98.         Query = "Author1LastName LIKE '*" & CGI_FormTuples(0).Value & "*' OR Author2LastName LIKE '*" & CGI_FormTuples(0).Value & "*' "
  99.         StartDBReply
  100.         If CGI_NumFormTuples < 1 Then
  101.             Send ("<H2>No Query Entered</H2>")
  102.         Else
  103.  
  104.             Set MyDB = OpenDatabase("C:\httpd\cgi-win\ibooks.MDB")   ' Open a database.
  105.             Set MySet = MyDB.CreateDynaset("Book Collection")
  106.             MySet.FindFirst Query
  107.             If MySet.NoMatch Then
  108.                 Send ("<H2>No Match in Database for Author " & CGI_FormTuples(0).Value & " </H2>")
  109.             Else
  110.                 Auth1First = "" & MySet.Fields("Author1FirstName").Value
  111.                 Auth1Last = "" & MySet.Fields("Author1LastName").Value
  112.                 Auth2First = "" & MySet.Fields("Author2FirstName").Value
  113.                 Auth2Last = "" & MySet.Fields("Author2LastName").Value
  114.                 ISBN = MySet.Fields("ISBNNumber")
  115.                 Title = MySet.Fields("Title")
  116.                 Send ("<H2>Match(s) for Author " & CGI_FormTuples(0).Value & " </H2>")
  117.                 Send ("<P>Title: " & Title & "</P>")
  118.                 Send ("<P>Author: " & Auth1First & " " & Auth1Last & "</P>")
  119.                 If Auth2Last <> "" Then
  120.                     Send ("<P>Author: " & Auth2First & " " & Auth2Last & "</P>")
  121.                 End If
  122.                 Send ("<P>ISBN Number: " & ISBN & "</P>")
  123.                 While MySet.NoMatch = False
  124.                     MySet.FindNext Query
  125.                     If MySet.NoMatch = False Then
  126.                         Send ("<HR>")
  127.                         Auth1First = "" & MySet.Fields("Author1FirstName").Value
  128.                         Auth1Last = "" & MySet.Fields("Author1LastName").Value
  129.                         Auth2First = "" & MySet.Fields("Author2FirstName").Value
  130.                         Auth2Last = "" & MySet.Fields("Author2LastName").Value
  131.                         ISBN = MySet.Fields("ISBNNumber")
  132.                         Title = MySet.Fields("Title")
  133.                         Send ("<P>Title: " & Title & "</P>")
  134.                         Send ("<P>Author: " & Auth1First & " " & Auth1Last & "</P>")
  135.                         If Auth2Last <> "" Then
  136.                             Send ("<P>Author: " & Auth2First & " " & Auth2Last & "</P>")
  137.                         End If
  138.                         Send ("<P>ISBN Number: " & ISBN & "</P>")
  139.                     End If
  140.                 Wend
  141.             End If
  142.             MySet.Close
  143.             MyDB.Close
  144.         End If
  145.  
  146.     End Select
  147.     
  148.     '
  149.     ' Finish up with server admin's address. Return to complete HTTP.
  150.     '
  151.     Send ("<HR>")
  152.     Send ("<A HREF=""mailto:" & CGI_ServerAdmin & """>")
  153.     Send ("<address><" & CGI_ServerAdmin & "></address>")
  154.     Send ("</A></BODY></HTML>")
  155.  
  156.     '****** RETURN, DON'T STOP! ******
  157. End Sub
  158.  
  159. Sub StartDBReply ()
  160.     Send ("Content-type: text/html")
  161.     Send ("X-Script-name: Visual Basic Access CGI ")
  162.     Send ("")
  163.     Send ("<HTML><HEAD><TITLE>Database Lookup Results</TITLE></HEAD>")
  164.     Send ("<BODY><H1>Database Lookup Results</H1>")
  165.     Send ("<HR>")
  166.  
  167. End Sub
  168.  
  169. Sub StartDocument (sel As String)
  170.     Send ("Content-type: text/html")
  171.     Send ("X-Script-name: Visual Basic CGI Test 1.1")
  172.     Send ("")
  173.     Send ("<HTML><HEAD><TITLE>CGI Test Results</TITLE></HEAD>")
  174.     Send ("<BODY><H1>CGI Test Results</H1>")
  175.     Send ("Program version: 1.1 (12-Nov-94)<BR>")
  176.     Send ("Server: <B>" & CGI_ServerSoftware & "</B><BR>")
  177.     Send ("Selector: <B>" & sel & "</B><P>")
  178.     Send ("<A HREF=""/cgitest.htm"">Return to usage document</A>")
  179.     Send ("<HR>")
  180. End Sub
  181.  
  182.